package com.itheima.service;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.itheima.domain.db.UserInfo;
import com.itheima.mapper.UserInfoMapper;
import com.itheima.vo.PageBeanVo;
import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.factory.annotation.Autowired;

@DubboService
public class UserInfoServiceImpl implements UserInfoService {

    @Autowired
    private UserInfoMapper userInfoMapper;

    // 保存用户信息
    @Override
    public void save(UserInfo userInfo) {
        userInfoMapper.insert(userInfo);
    }

    @Override
    public void update(UserInfo userInfo) {
        QueryWrapper<UserInfo> uq = new QueryWrapper<>();
        userInfoMapper.updateById(userInfo);
    }

    @Override
    public UserInfo findUserInfoById(Long id) {
        return userInfoMapper.selectById(id);
    }

    @Override
    public UserInfo select(Long id) {
        return userInfoMapper.selectById(id);
    }
    //用户查询
    @Override
    public PageBeanVo findAll(Integer pageNum, Integer pageSize) {
        //开启分页
        Page<UserInfo> page = new Page<>(pageNum, pageSize);
       page= userInfoMapper.selectPage(page,null);
        return new PageBeanVo(pageNum,pageSize,page.getTotal(),page.getRecords());
    }
}